package b1w1nn1ng.crossf1t.tests;
import b1w1nn1ng.crossf1t.business.*;
import b1w1nn1ng.crossf1t.db.*;
import java.sql.SQLException;

import junit.framework.TestCase;

import org.junit.*;
import static org.junit.Assert.*;


public class TestUser extends TestCase{

	User user1, user2, user3, user4;
	Goal goal1,goal2;
	
	protected void setUp(){
		//initialize 4 users
		user1 = new User("User one", "I am user one", "UserOne@gmail.com", "User 1 first name",
				"User 1 last name", "Who is the first user?", "User 1 is the first user", 1111,
				111, 61);
		user2 = new User("User two", "I am user two", "UserTwo@gmail.com", "User 2 first name",
				"User 2 last name", "Who is the second user?", "User 2 is the second user", 2222,
				222, 62);
		user3 = new User("User three", "I am user three", "UserThree@gmail.com", "User 3 first name",
				"User 3 last name", "Who is the third user?", "User 3 is the third user", 3333,
				333, 63);
		user4 = new User("User four", "I am user four", "UserFour@gmail.com", "User 4 first name",
				"User 4 last name", "Who is the fourth user?", "User 4 is the fourth user", 4444,
				444, 64);
		
		goal1 = new Goal("bench over 9000 pounds",true);
		goal2 = new Goal("2nd goal here",true);
	}
	
	
	public void testAddFriend() throws SQLException, ClassNotFoundException
	{
		//add user 2 as a friend of user 1
		user1.addFriend(user2.getUsername());
		//make sure user 1 has user 2 as a friend
		assertTrue(user1.getFriends().contains(user2.getId()));
		//make sure user 2 has user 1 as a friend
		assertTrue(user2.getFriends().contains(user1.getId()));
		
		//add user 2 as a friend of user 1 again. make sure it returns false
		assertFalse(user1.addFriend(user2.getUsername()));
		
		
		
		//add user 3 as a friend of user 1
		user1.addFriend(user3.getUsername());
		//make sure user 1 has user 3 as a friend
		assertTrue(user1.getFriends().contains(user3.getId()));
		//make sure user 3 has user 1 as a friend
		assertTrue(user3.getFriends().contains(user1.getId()));
		//make sure user 2 and user 3 are NOT friends
		assertFalse(user2.getFriends().contains(user3.getId()));
		assertFalse(user3.getFriends().contains(user2.getId()));
		
		
	}
	
	public void testRemoveFriend() throws SQLException, ClassNotFoundException
	{
		//add user 2 as a friend of user 1
		user1.addFriend(user2.getUsername());
		//make user 1 remove user 2 from his friends list
		user2.removeFriend(user1.getUsername());
		//check that user 1 no longer has user 2 as a friend
		assertFalse(user1.getFriends().contains(user2.getId()));
		//check that user 2 no longer has user 1 as a friend
		assertFalse(user2.getFriends().contains(user1.getId()));
		
		
		
		//add user 2,3,4 as friends of user 1
		user1.addFriend(user2.getUsername());
		user1.addFriend(user3.getUsername());
		user1.addFriend(user4.getUsername());
		//remove user 3 from user 1's friends
		user1.removeFriend(user3.getUsername());
		//check that user 1 no longer has user 3 as a friend
		assertFalse(user1.getFriends().contains(user3.getId()));
		//check that user 3 no longer has user 1 as a friend
		assertFalse(user3.getFriends().contains(user1.getId()));
		
		//check that user 1 is still friends with user 2 and 4
		assertTrue(user1.getFriends().contains(user2.getId()));
		assertTrue(user1.getFriends().contains(user4.getId()));

		//check that user 2 is still friends with user 1
		assertTrue(user2.getFriends().contains(user1.getId()));
		//check that user 4 is still friends with user 1
		assertTrue(user4.getFriends().contains(user1.getId()));
	}
	
	public void testAddGoal()
	{
		//add a goal to user 1
		user1.addGoal(goal1);
		//check that the goal is there
		assertTrue(user1.getGoals().contains(goal1));
		
		//add another goal to user 1
		user1.addGoal(goal2);
		//check that both goals are still there
		assertTrue(user1.getGoals().contains(goal1));
		assertTrue(user1.getGoals().contains(goal2));
		
	}
	
	public void testRemoveGoal()
	{
		//add a goal
		user1.addGoal(goal1);
		//remove the goal
		user1.deleteGoal(goal1);
		//check that the goal is removed
		assertFalse(user1.getGoals().contains(goal1));
		
		//add 2 goals of the same name
		user1.addGoal(goal1);
		user1.addGoal(goal1);
		//remove one of the goals
		user1.deleteGoal(goal1);
		//check that one of the goals is still present
		assertTrue(user1.getGoals().contains(goal1));
	}
	public void getUserByUsername() throws SQLException, ClassNotFoundException{
		User user = User.getUserByUsername("a2hill");
		assertTrue(user.getFirstName().equals("austin"));
		assertTrue(user.getLastName().equals("hill"));
	}
}
